import Vue from 'vue'
const KEY = "keywords";

var cache = {
    add:function(keyword){
        if(!keyword){
            return;
        }
        let list = []
        if(localStorage.getItem(KEY)){
            list = JSON.parse(localStorage.getItem(KEY))
        }
        
        let rs=list.filter((item)=>item===keyword)
        if(!rs.length){
            list.push(keyword)
        }
        localStorage.setItem(KEY,JSON.stringify(list))
        console.log("list")
        console.log(list)
    },
    get(){
        return JSON.parse(localStorage.getItem(KEY))
    },
    del(){
        let list = JSON.parse(localStorage.getItem(KEY))
        list.splice(0)
        localStorage.setItem(KEY,JSON.stringify(list))
    }
}

Vue.use({
    install(vue){
        vue.prototype.$cache = cache
    }
})